package com.ycp.erp.supplier.ui.binder;

import android.widget.ImageView;
import android.widget.TextView;

import com.one.common.view.multitytype.adapter.BaseItemBinder;
import com.one.common.view.multitytype.adapter.BaseViewHolderMulti;
import com.ycp.erp.R;
import com.ycp.erp.supplier.model.bean.SupplierBean;

import androidx.annotation.NonNull;

/**
 * Class Des:
 * Created by bjh on 2021/9/1.
 */
public class SupplierManagerBinder extends BaseItemBinder<SupplierBean> {
    public SupplierManagerBinder() {
        super(R.layout.item_supplier_manager);
    }

    @Override
    protected void bindView(@NonNull BaseViewHolderMulti holder, @NonNull SupplierBean item) {
        ImageView ivSelect = holder.getView(R.id.ivSelect);
        TextView tvCircleName = holder.getView(R.id.tvCircleName);
        TextView tvName = holder.getView(R.id.tvName);
        TextView tvPhone = holder.getView(R.id.tvPhone);
        tvCircleName.setText(item.getFirstName());
        tvName.setText(item.getName());
        tvPhone.setText(item.getPhone());
        if (item.isSelected()) {
            ivSelect.setImageResource(R.mipmap.ic_selected_circle);
        } else {
            ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
        }
        holder.getView(R.id.rlItem).setOnClickListener(v -> {
            item.setSelected(!item.isSelected());
            if (item.isSelected()) {
                ivSelect.setImageResource(R.mipmap.ic_selected_circle);
            } else {
                ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
            }
        });
    }
}
